package com.wzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wzy.domain.ResponseResult;
import com.wzy.domain.entity.Link;
import com.wzy.domain.vo.LinkListVO;
import com.wzy.mapper.LinkMapper;
import com.wzy.service.LinkService;
import com.wzy.util.BeanCopyUtils;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.wzy.constant.SystemConstants.NORMAL_STATUS;

/**
 * 友链业务层
 */
@Service
public class LinkServiceImpl extends ServiceImpl<LinkMapper, Link>
        implements LinkService
{

    /**
     * 查询所有友链
     */
    @Override
    public ResponseResult<List<LinkListVO>> getAllLink()
    {
        LambdaQueryWrapper<Link> queryWrapper = new LambdaQueryWrapper<>();
        // 查询所有审核通过的友链
        queryWrapper.eq(Link::getLinkStatus, NORMAL_STATUS);
        List<Link> links = this.list(queryWrapper);

        List<LinkListVO> linkListVOS = BeanCopyUtils.copyBeanList(links, LinkListVO.class);

        return ResponseResult.okResult(linkListVOS);
    }
}



